package main

import (
	"sync"

	"github.com/aceld/zinx/ziface"
	"github.com/asim/go-micro/v3"
	"github.com/asim/go-micro/v3/client"
	"github.com/gin-gonic/gin"
	"github.com/redis/go-redis/v9"
	clientv3 "go.etcd.io/etcd/client/v3"
	"go.uber.org/zap"
	"smeb.xyz/pub/websocket-subandpub-cluster/internal/handlerwebsocket/protos"
)

// Config
var Configs *Config

// Redis
var Redis *redis.Client

// 日志
var ZapLogger *zap.SugaredLogger
var EtcdUtil *clientv3.Client

// Zinx Server
var ZinxServer ziface.IServer

// 微服务名称
var ServerName string = ""

// Grpc Service
var Service micro.Service

var Gin *gin.Engine

var GrpcService map[string]protos.GrpcService = make(map[string]protos.GrpcService)

var GrpcClient client.Client

var Mutexs map[string]*sync.Mutex = make(map[string]*sync.Mutex)

var ChannelUserSubs map[string][]uint64 = make(map[string][]uint64)

var UserChannels map[uint64][]string = make(map[uint64][]string)

var IdentityConnections map[uint64]uint64 = make(map[uint64]uint64)

var Channel_Redis_key string = "channel"

var ConnId_Redix_key string = "connid"

//	@title			Swagger Example API
//	@version		1.0
//	@description	This is a sample server celler server.
//	@termsOfService	http://www.asihe.cn

//	@contact.name	API Support
//	@contact.url	http://www.asihe.cn
//	@contact.email	1292441381@qq.com

//	@license.name	Apache 2.0
//	@license.url	http://www.apache.org/licenses/LICENSE-2.0.html

//	@host		localhost:8080
//	@BasePath	/api/v1

func main() {
	config, error := CreateConfig()
	if error != nil {
		panic(error)
	}
	Configs = &config
	GrpcClient = InitGrpcClient(Configs.EtcdUrls)
	ServerName = "go.micro.api.socket.server." + GetRandomString(18)
	Redis = CreateRedisClient(Configs.RedisAddress, Configs.Password)
	ZapLogger = CreateLogger()
	go InitWebServer()
	go StartAZinxServer()
	go StartManageConsole()
	InitGrpcServer()

}
